use std::io;
use rand::Rng;
use std::cmp::Ordering;

fn main() {
    println!("Hello, world!");

    let s_number = rand::rng().random_range(1..=100);
    // println!("The secret number is: {}", s_number);

    loop {
        println!("please input your guess.");
        let mut guess = String::new();
    
        io::stdin()
            .read_line(&mut guess)
            .expect("failed to read line");

        // let guess:u32 = guess.trim().parse().expect("Please type a number");
        let guess:u32 = match guess.trim().parse() {
            Ok(num) => num,
            Err(_) => continue,
        };
        println!("your guessed: {}",guess);

        match guess.cmp(&s_number) {
            Ordering::Less => println!("Too small!"),
            Ordering::Greater => println!("Too big!"),
            Ordering::Equal => {println!("You win!"); break;}
        }  
    }
   
}
